// **************根据id获取到上个页面的值*****************

$(function () {

    var form = layui.form
    // 获取用户id
    let id = new URLSearchParams(location.search).get('id')

    function loadUserInfo() {
        $.ajax({
            url: 'http://localhost:8888/admin/users/' + id,
            success: function (res) {
                if (res.status === 0) {
                    form.val('edit-Form', res.data)
                } else {
                    layer.msg(res.message)
                }
            },
            // headers: {
            //     'Authorization': "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWQiOjEsImlhdCI6MTU5OTUyNjEwMywiZXhwIjoxNTk5NTI5NzAzfQ.ZGV7c2JfVhtylimi_LbAFm2HD_dt1n-h0J-eFWhxdzM"
            // },
            headers: {
                Authorization: localStorage.getItem('token')
            },
        })
    }
    loadUserInfo()

    // *************修改用户表单提交事件********************
    $('.layui-form').submit(function (e) {
        e.preventDefault()
        var fd = $(this).serialize()
        $.ajax({
            type: 'PUT',
            url: 'http://localhost:8888/admin/users',
            data: fd,
            success: function (res) {
                layer.msg(res.message)
            },
            // headers: {
            //     'Authorization': "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWQiOjEsImlhdCI6MTU5OTUyNjEwMywiZXhwIjoxNTk5NTI5NzAzfQ.ZGV7c2JfVhtylimi_LbAFm2HD_dt1n-h0J-eFWhxdzM"
            // },
            headers: {
                Authorization: localStorage.getItem('token')
            },
        })
    })

})